
<template>
  <div class="dashboard-container">
    <el-drawer ref="drawer" size="600px" :title="status==1?'新增':'编辑'" :visible.sync="showDialog" :wrapper-closable="true" @close="close">
      <div class="detial">
        <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="120px" class="demo-ruleForm">
          <el-row :gutter="10">
            <el-col :span="24">
              <el-form-item label="运单号:" prop="waybill_no">
                <el-input
                  v-model="ruleForm.waybill_no"
                  placeholder="运单号"
                />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="调整类型:" prop="type">
                <el-select
                  v-model="ruleForm.type"
                  style="width:100%"
                  placeholder="请选择调整类型"
                >
                  <el-option
                    v-for="(item,index) in adjustTypeList"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="调整金额:" prop="adjust_amount">
                <el-input
                  v-model="ruleForm.adjust_amount"
                  placeholder="调整金额"
                />
                <div style="font-size:12px;color:red">
                  调整金额只针对余额, +就是余额+,-就是余额-
                </div>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="结算用户:" prop="uid">
                <el-select
                  v-model="ruleForm.uid"
                  filterable
                  style="width:100%"
                  placeholder="请选择结算用户"
                >
                  <el-option
                    v-for="(item,index) in memberList"
                    :key="index"
                    :label="item.username"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="备注:" prop="remark">
                <el-input v-model="ruleForm.remark" type="textarea" placeholder="请输入备注" />
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>
      </div>
      <div class="buttons">
        <el-button
          v-if="status == 1"
          size="mini"
          type="primary"
          style="margin-left:20px"
          @click="addNews()"
        >
          新 增
        </el-button>
        <el-button
          v-if="status == 2"
          size="mini"
          type="primary"
          style="margin-left:20px"
          @click="editNews()"
        >
          保 存
        </el-button>
        <el-button
          size="mini"
          type=""
          @click="close()"
        >
          取消
        </el-button>

      </div>

    </el-drawer>
  </div>
</template>

<script>
import { adjustAmount } from '@/api/finance/index'

export default {
  name: 'Detial',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    detial: {
      require: false,
      type: Object,
      default: () => {

      }
    },
    memberList: {
      require: false,
      type: Array,
      default: () => {

      }
    },
    adjustTypeList: {
      require: false,
      type: Array,
      default: () => {

      }
    },
    status: {
      type: Number,
      default: 1
    }
  },
  data() {
    return {
      time: '',
      showDialog: false,
      flightList: [],
      flightDetial: { port_sheet: {}},
      ruleForm: {
        'uid': '',
        'type': '',
        'adjust_amount': '',
        'remark': '',
        'waybill_no': ''
      },
      rules: {
        uid: [
          { required: true, message: '请选择结算用户' }
        ],
        type: [
          { required: true, message: '请选择账单类型' }
        ],
        adjust_amount: [
          { required: true, message: '请输入调整金额' }
        ]
      }
    }
  },
  watch: {
    visible(val) {
      this.showDialog = this.visible
      if (!this.showDialog) {
        this.resetForm()
      }
    }
  },
  mounted() {
  },
  methods: {
    close() {
      this.$emit('update', false)
    },
    resetForm() {
      this.$refs['ruleForm'].resetFields()
      this.flightDetial = { port_sheet: {}}
      this.ruleForm = {
        'uid': '',
        'type': '',
        'adjust_amount': '',
        'remark': '',
        'waybill_no': ''
      }
    },
    addNews() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          adjustAmount(this.ruleForm).then(res => {
            this.$message.success('添加成功')
            this.$emit('reload')
          })
        } else {
          return false
        }
      })
    }

  }

}
</script>
<style scoped>
.detial{
  padding:40px 40px 20px 20px;
}
.buttons{
  display: flex;
  flex-direction: row-reverse;
  padding-right: 40px;
}
</style>
